//
//  WelcomeNewFeatureController.swift
//  lixiangweibo
//
//  Created by dyy on 15/11/29.
//  Copyright © 2015年 lixianggongzuoshi. All rights reserved.
//

import UIKit
import SnapKit
import SDWebImage
class WelcomeNewFeatureController: UIViewController {

    
    override func loadView() {
        view = backImage
    }
    override func viewDidLoad() {
        super.viewDidLoad()

        setUpUI()
        
        IconImage.sd_setImageWithURL(AccountViewModel().headerImageUrl, placeholderImage: UIImage(named: "ad_background"))
    }
    
    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
        
        startAnimation()
    }
    
    private func setUpUI(){
    
        view.addSubview(IconImage)
        view.addSubview(welcomeLabel)
        
        IconImage.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(view.snp_centerX)
            make.size.equalTo(CGSizeMake(90, 90))
            make.bottom.equalTo(view.snp_bottom).offset(-180)
        }
        
        welcomeLabel.snp_makeConstraints { (make) -> Void in
            
            make.centerX.equalTo(IconImage.snp_centerX)
            make.top.equalTo(IconImage.snp_bottom).offset(20)
        }
        
        IconImage.layer.cornerRadius = 45
        IconImage.layer.masksToBounds = true
        
    }
    private func startAnimation(){
    
    let offset = -UIScreen.mainScreen().bounds.size.height + 180
        IconImage.snp_makeConstraints { (make) -> Void in
            
            make.bottom.equalTo(view.snp_bottom).offset(offset)
        }
        
        UIView.animateWithDuration(1, delay: 0, usingSpringWithDamping: 0.9, initialSpringVelocity: 9.8, options: [], animations: { () -> Void in
            
            self.view.layoutIfNeeded()
            
            }) { (_) -> Void in
                
NSNotificationCenter.defaultCenter().postNotificationName(WBSwitchRootNotification, object: nil)
        
        }

        
    }


    private lazy var backImage: UIImageView = UIImageView(image: UIImage(named: "ad_background"))
    private lazy var IconImage: UIImageView = UIImageView()
    
    private lazy var welcomeLabel: UILabel = {
    
    let l = UILabel()
        l.text = (AccountViewModel().userName ?? "") + "  欢迎归来"
        l.textColor = UIColor.grayColor()
        l.font = UIFont.systemFontOfSize(18)
        l.sizeToFit()
        return l

    }()
    

}
